<?php if (!defined('THINK_PATH')) exit();?> <!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>管理界面</title>

    <!-- Bootstrap -->
    <link href="/IM/Public/css/bootstrap.min.css" rel="stylesheet">

    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="/IM/Public/js/bootstrap.min.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>


  <?php
 session_start(); if(!isset($_SESSION['username'])) { echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='http://128.199.209.239/IM/index.php/Home/Console/login';"; echo "</script>"; } ?>


  <div>
    <input type="hidden" value="<?php echo ($baseurl); ?>" id="baseurl">
  </div>

  <div class="board">
    <h1>Cybersys</h1>
  </div>
  <br/>

  

<div>
  <input type="hidden" value="<?php echo ($parent['id']); ?>" id="parent_id" />
  <input type="hidden" value="<?php echo ($parent['name']); ?>" id="parent_name" />
</div>

  <div class="board">

    <div>
      <table class="table table-bordered">
        <colgroup>
          <col width="12%"></col><col width="12%"></col><col width="12%"></col><col width="18%"></col><col width="18%"></col><col width="18%"></col><col width="10%"></col>
        </colgroup>

        <?php if(is_array($menu_list)): foreach($menu_list as $id=>$vo): ?><tr>
              <td><input type="text" value="<?php echo ($vo["menu_name_en"]); ?>" id="menu_name_en<?php echo ($vo["menu_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["menu_name_sc"]); ?>" id="menu_name_sc<?php echo ($vo["menu_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["menu_name_tc"]); ?>" id="menu_name_tc<?php echo ($vo["menu_id"]); ?>"></td>
              <td><a href="<?php echo ($baseurl); ?>Console/link/menu_id/<?php echo ($vo["menu_id"]); ?>/parent_name/<?php echo ($vo["menu_name_en"]); ?>/parent_id/<?php echo ($vo["menu_id"]); ?>"><button class="btn btn-info">expand</button></a></td>
            </tr><?php endforeach; endif; ?>

        <?php if(is_array($link_list)): foreach($link_list as $id=>$vo): ?><tr>
              <td><input type="text" value="<?php echo ($vo["link_name_en"]); ?>" id="link_name_en<?php echo ($vo["link_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["link_name_sc"]); ?>" id="link_name_sc<?php echo ($vo["link_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["link_name_tc"]); ?>" id="link_name_tc<?php echo ($vo["link_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["link_addr_en"]); ?>" id="link_addr_en<?php echo ($vo["link_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["link_addr_sc"]); ?>" id="link_addr_sc<?php echo ($vo["link_id"]); ?>"></td>
              <td><input type="text" value="<?php echo ($vo["link_addr_tc"]); ?>" id="link_addr_tc<?php echo ($vo["link_id"]); ?>"></td>
              <td><button id="<?php echo ($vo["link_id"]); ?>" class="btn btn-info link_save"> save </button>
              <button id="<?php echo ($vo["link_id"]); ?>" class="btn btn-info link_del"> delete </button></td>
            </tr><?php endforeach; endif; ?>
      </table>
    </div>

    <br/>

    <div>
      <button id="add" class="btn btn-info"> add </button> <span style="padding-right:10px;"></span>
    </div>
    <br/>


    <div id="add" style="display:none;">
      <table class="table table-bordered">
        <tr><td>name(en)</td><td>name(sc)</td><td>name(tc)</td><td>url(en)</td><td>url(sc)</td><td>url(tc)</td></tr>
        <tr>
          <td><input type="text" value="" id="name_en" placeholder="英文" /></td>
          <td><input type="text" value="" id="name_sc" placeholder="简体" /></td>
          <td><input type="text" value="" id="name_tc" placeholder="繁体" /></td>
          <td><input type="text" value="" id="url_en" placeholder="http://" /></td>
          <td><input type="text" value="" id="url_sc" placeholder="http://" /></td>
          <td><input type="text" value="" id="url_tc" placeholder="http://" /></td>
        </tr>
      </table>
      <button class="btn btn-info" id="newSave"> save </button>
    </div>
  </div>

  <br/>



  <div class="board">
    <div id="operation">
      <a href="http://128.199.209.239/"><button class="btn btn-info"> console panel</button></a> <span style="padding-right:10px;"></span>
      <a href="<?php echo ($baseurl); ?>Console"><button class="btn btn-info"> xml panel</button></a> <span style="padding-right:10px;"></span>
      <a href="<?php echo ($baseurl); ?>Console/newsList"><button class="btn btn-info"> news panel</button></a> <span style="padding-right:10px;"></span>
      <a href="<?php echo ($baseurl); ?>Console/welcome"><button class="btn btn-info"> welcome panel</button></a> <span style="padding-right:10px;"></span>
      <a href="<?php echo ($baseurl); ?>Console/photoFolderEdit"><button class="btn btn-info"> photo panel</button></a> <span style="padding-right:10px;"></span>
      <button class="btn btn-info" id="back"> back </button> <span style="padding-right:10px;"></span>
      <button class="btn btn-info" id="logout">logout</button>  <span style="padding-right:10px;"></span>
    </div
  <br/>  

  <style type="text/css">
    input {
      width: 100%;
      border: 1px solid transparent;
    }

    div.board{
      margin-left: 50px;
      margin-right: 50px;
    }

    ul, li, ul>li{
      display: inline;
      text-decoration: none;
    }
  </style>


  <script type="text/javascript">

  var baseurl = $("#baseurl").val();

$(document).ready(function(){
  $(".link_save").click(function(){
    var link_id = $(this).attr("id");
    var link_name_en = $("#link_name_en"+link_id).val();
    var link_name_sc = $("#link_name_sc"+link_id).val();
    var link_name_tc = $("#link_name_tc"+link_id).val();
    var link_addr_en = $("#link_addr_en"+link_id).val();
    var link_addr_sc = $("#link_addr_sc"+link_id).val();
    var link_addr_tc = $("#link_addr_tc"+link_id).val();

    //alert(tc);

    $.ajax({
      type: "POST",
      url: baseurl+"Link/edit",
      dataType:"json",
      data:{
        link_id: link_id,
        link_name_en: link_name_en,
        link_name_sc: link_name_sc,
        link_name_tc: link_name_tc,
        link_addr_en: link_addr_en,
        link_addr_sc: link_addr_sc,
        link_addr_tc: link_addr_tc,
        
      },
      beforeSend: function(){       
      },
      success: function(data){
        if(data["success"]==1){
          alert("修改成功！");
        }
        else{
          alert(data["error"]);            
        }
      }
    });
  });

  $(".link_del").click(function(){
    var confirm = window.confirm("Delete the link?");
    if(confirm){
      var link_id = $(this).attr("id");
      $.ajax({
        type: "POST",
        url: baseurl+"Link/del",
        dataType:"json",
        data:{
          link_id: link_id,
        },
        success: function(data){
          if(data["success"]==1){
            alert("删除成功！");
            location.reload();  
          }
          else{
            alert(data["error"]);            
          }
          location.reload();
        }
      });      
    }
  });

  $(".menu_save").click(function(){
    var menu_id = $(this).attr("id");
    var menu_name_en = $("#menu_name_en"+menu_id).val();
    var menu_name_sc = $("#menu_name_sc"+menu_id).val();
    var menu_name_tc = $("#menu_name_tc"+menu_id).val();

    $.ajax({
      type: "POST",
      url: baseurl+"Menu/edit",
      dataType:"json",
      data:{
        menu_id: menu_id,
        menu_name_en: menu_name_en,
        menu_name_sc: menu_name_sc,
        menu_name_tc: menu_name_tc,
        
      },
      beforeSend: function(){       
      },
      success: function(data){
        if(data["success"]==1){
          alert("修改成功！");
        }
        else{
          alert(data["error"]);            
        }
      }
    });
  });

  $("button.folder_save").click(function(){
    var folder_id = $(this).attr("id");
    var folder_name_en = $("#folder_name_en"+folder_id).val();
    var folder_name_sc = $("#folder_name_sc"+folder_id).val();
    var folder_name_tc = $("#folder_name_tc"+folder_id).val();


    $.ajax({
      type: "POST",
      url: baseurl+"Photo/folderEdit",
      dataType:"json",
      data:{
        folder_id: folder_id,
        folder_name_en: folder_name_en,
        folder_name_sc: folder_name_sc,
        folder_name_tc: folder_name_tc,
        
      },
      beforeSend: function(){       
      },
      success: function(data){
        if(data["success"]==1){
          alert("修改成功！");
          window.location.reload();
        }
        else{
          alert(data["error"]);
        }
      }
    });
  });


  $("button#folderAdd").click(function(){
    var folder_name_en = $("#folder_name_en").val();
    var folder_name_sc = $("#folder_name_sc").val();
    var folder_name_tc = $("#folder_name_tc").val();

    $.ajax({
      type: "POST",
      url: baseurl+"Photo/folderAdd",
      dataType:"json",
      data:{
        folder_name_en: folder_name_en,
        folder_name_sc: folder_name_sc,
        folder_name_tc: folder_name_tc,
        
      },
      beforeSend: function(){       
      },
      success: function(data){
        if(data["success"]==1){
          alert("添加成功！");
          window.location.reload();
        }
        else{
          alert(data["error"]);
        }
      }
    });
  });

  $("button.folder_delete").click(function(){
    var folder_id = $(this).attr("id");

    $.ajax({
      type: "POST",
      url: baseurl+"Photo/folderDelete",
      dataType:"json",
      data:{
        folder_id: folder_id,
      },
      beforeSend: function(){       
      },
      success: function(data){
          alert("删除成功！");
          location.reload();
      }
    });
  });




  $("#back").click(function(){
    window.history.back();
  });

  $("button#add").click(function(){
    $("div#add").show();
  });

  var url = window.location.href;
  var homepage = baseurl+"Console/";
  if(url == homepage){
    $("button#add").hide();
    $("button#back").hide();
    $("button.menu_save").hide();
  }

  $("#newSave").click(function(){
    var link_name_en = $("#name_en").val();
    var link_name_sc = $("#name_sc").val();
    var link_name_tc = $("#name_tc").val();
    var link_addr_en = $("#url_en").val();
    var link_addr_sc = $("#url_sc").val();
    var link_addr_tc = $("#url_tc").val();
    var parent_id = $("#parent_id").val();
    var parent_name = $("#parent_name").val();

    $.ajax({
      type: "POST",
      url: baseurl+"Link/add",
      dataType:"json",
      data:{
        link_name_en: link_name_en,
        link_name_sc: link_name_sc,
        link_name_tc: link_name_tc,
        link_addr_en: link_addr_en,
        link_addr_sc: link_addr_sc,
        link_addr_tc: link_addr_tc,
        parent_name: parent_name,
        parent_id, parent_id,
        font_size:19,
        
      },
      beforeSend: function(){       
      },
      success: function(data){
        if(data["success"]==1){
          alert("添加成功！");
        }
        else{
          alert(data["error"]);            
        }
        location.reload();
      }
    });
  });

 //

  $("#logout").click(function(){
    $.ajax({
      type: "POST",
      url: baseurl+"Device/logout",
      success: function(data){
      window.location.href=baseurl+"Console/";
      }
    });
  });

  // create new xml file
  $("#create").click(function(){
    $.ajax({
      type: "POST",
      url: baseurl+"Xml/newXml",
      success: function(data){
        alert("ok");
      }
    });    
  });

});

  </script>


  </body>
</html>